package com.frogs.ucenter.controller;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.frogs.framework.component.cache.Cache;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.ucenter.component.UserPermissionHelper;
import com.frogs.ucenter.service.TagService;

@Controller
public class TagController extends AbsController {

	private static Logger log = LoggerFactory.getLogger(TagController.class);

	private final static String TAG_LIST_BY_AGE_AND_SEX = "/tag/listByAgeAndSex";
	
	@Resource
	private UserPermissionHelper userPermissionHelper;
	@Resource(name="tagService")
	private TagService tagService;
	
	@Resource(name="xmemcached")
	private Cache cache;
	
	/**
	 * 添加用户标签
	 * @param request
	 * @return
	 */
	@RequestMapping(TAG_LIST_BY_AGE_AND_SEX)
	public JSONObject listTagByAgeAndSex(HttpServletRequest request) {
		try {
			HttpRequestInfo requestInfo = new HttpRequestInfo(request);
			
			
			Integer sex = requestInfo.getIntParameter(ApiUrlParamEnum.sex.getParamName(), 0);
			Integer age = requestInfo.getIntParameter(ApiUrlParamEnum.age.getParamName(), 0);
			
			JSONObject json = tagService.getTagListBySexaAge(sex, age);
			
			return json;
		} catch (Exception e) {
			log.error("func[listTagByAgeAndSex] parameterMap[{}] exception[{} - {}] desc[fail]",//
					new Object[] { request.getParameterMap(), e.getMessage(), Arrays.deepToString(e.getStackTrace()) });
		}
		return null;
	}
	
}
